package gold.digger;

import gold.utils.InputUtil;

import java.util.Arrays;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC2028 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int[] missingRolls(int[] rolls, int mean, int n) {
            int curSum = Arrays.stream(rolls).sum(), needSum = mean * (rolls.length + n) - curSum;
            if (needSum > n * 6 || needSum < n) return new int[0];
            int needMean = needSum / n, shouldAddCnt = needSum % n, i = 0;
            int[] ans = new int[n];
            for (; i < shouldAddCnt; i++) ans[i] = needMean + 1;
            for (; i < n; i++) ans[i] = needMean;
            return ans;
        }
    }

    public void run() {
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[3,2,4,3]"), 4, 2)));
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[1,5,6]"), 3, 4)));
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[1,2,3,4]"), 6, 4)));
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[1]"), 3, 1)));
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[6,3,4,3,5,3]"), 1, 6)));
        System.out.println(Arrays.toString(new Solution().missingRolls(InputUtil.toIntegerArray("[4,5,6,2,3,6,5,4,6,4,5,1,6,3,1,4,5,5,3,2,3,5,3,2,1,5,4,3,5,1,5]"), 4, 40)));
    }

    public static void main(String[] args) throws Exception {
        LC2028 an = new LC2028();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
